const { json } = require('express')
const express = require('express')
const path = require('path')
const request = require('request')

const app = express()

app.set('view engine','ejs')
app.use('/public',express.static(path.join(__dirname,'./public')))
app.get('/',(req,res)=>{
    // res.render('新闻列表')
    request({
        url:'http://v.juhe.cn/toutiao/index?type=top&key=807f10d5da886d846acdde0d7c34024d',
        method: 'get',
        headers:{
            'Content-Type':'application/json'
        }
        // body:{

        // }

    },(err,response,body)=>{
        console.log(err);
        console.log(response);
        console.log(body);
        let news = JSON.parse(body).result.data
        res.render('newslist',{news})
    })
})
app.listen(3000,()=>{
    console.log(`服务已启动`);
})